package com.zmn.oms.dubbo.config;

import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 类描述：线程池配置
 * @author lujia
 * @date 2018/11/23 19:53
 */
@Configuration
public class ThreadPoolConfig {

    private static int CORE_POOL_SIZE = 50;
    private static int MAX_POOL_SIZE = 50;

    @Bean(autowire = Autowire.BY_NAME,value = "dtsTaskAsyncPool")
    public Executor taskAsyncPool() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(CORE_POOL_SIZE);
        executor.setMaxPoolSize(MAX_POOL_SIZE);
        executor.setThreadNamePrefix("DubboAsyncExecutor-");
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        executor.initialize();
        return executor;
    }
}
